package nr.co.mhgames.polyanim.util;

import java.util.Locale;

/**
 * A simple vertex, from which polygons are constructed of.
 * 
 * @author Mika Halttunen
 */
public class Vertex implements Cloneable {
	/** Vertex position */
	public Vector2f position;


	public Vertex() {
		try {
			position = (Vector2f) Vector2f.ZERO.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
	}

	public Vertex(Vector2f pos) {
		position = pos;
	}

	public Vertex(float x, float y) {
		position = new Vector2f(x, y);
	}


	@Override
	public Object clone() throws CloneNotSupportedException {
		Vertex clone = (Vertex) super.clone();
		if (position != null)
			clone.position = (Vector2f) position.clone();

		return clone;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((position == null) ? 0 : position.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Vertex))
			return false;

		Vertex other = (Vertex) obj;
		if (position == null) {
			if (other.position != null)
				return false;
		} else if (!position.equals(other.position))
			return false;

		return true;
	}

	@Override
	public String toString() {
		return String.format((Locale) null, "Vertex: (%f, %f), %s", position.x, position.y, super
				.toString());
	}
}
